package topin.facecat.FaceCat.UI

import facecat.topin.core.FCSize
import facecat.topin.core.FCView
import facecat.topin.xml.FCUIXml
import org.w3c.dom.Node

open class UIXmlEx
    : FCUIXml() {
    private var m_scaleFactor = 1.0
    var scaleFactor: Double
        get() = m_scaleFactor
        set(value) {
            m_scaleFactor = value
            if (native != null) {
                native.paint.setScaleFactor(m_scaleFactor, m_scaleFactor)
            }
        }

    /**
     * 创建视图
     * @param node 节点
     * @param type 类型
     * @return 视图
     */
    override fun createView(node: Node, type: String): FCView? {
        return if (type == "mychart") {
            MyChart()
        } else if (type == "latestdiv") {
            LatestDiv()
        } else if (type == "securitylist") {
            SecurityList()
        } else {
            super.createView(node, type)
        }
    }

    /*
     * 重置缩放尺寸
     */
    fun resetScaleSize(clientSize: FCSize) {
        val inative = native
        if (inative != null) {
            val host = inative.host
            val nativeSize = inative.size
            inative.scaleSize = FCSize(
                (clientSize.cx * m_scaleFactor).toInt(),
                (clientSize.cy * m_scaleFactor).toInt()
            )
            inative.update()
        }
    }
}